<?php
/**
 * Created by PhpStorm.
 * User: zhongbaitong
 * Date: 2020/1/9
 * Time: 17:59
 */

namespace app\user\validate;

use app\common\validate\Base;
use app\user\model\UserFans;

class FansValidate extends Base
{
    protected $rule = [
        // 用一个必传的参数触发验证 medias 或 content 两者必须传一个
        "token" => "require",
        "obj_uid" => "require|checkInvalid"
    ];

    protected function checkInvalid($value, $rule='', $data='', $field=''){

        $user_id = $data["user_id"];
        $obj_uid = $data["obj_uid"];

        // 关注自己
        if($user_id == $obj_uid)
            return "不能关注自己..";

        // 已关注过
        $is_faned = UserFans::where(compact("user_id","obj_uid"))->count();
        if($is_faned)
            return "已关注过对方..";

        return true;
    }
}